package com.hs.server.runnable;

import com.hs.server.handler.InitHandle;
import com.hs.server.service.WebApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 程序启动端口完后再初始化方法
 */
@Component
@Order(value = 1)
@Slf4j
public class AfterRunner implements ApplicationRunner {
    @Autowired
    private InitHandle initHandle;
    @Autowired
    private WebApiService webApiService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("【程序启动完成】");
        initHandle.init();
        //判断整车是否结束线程
        Thread judgeThread = new Thread(() -> {
            while (true){
                try {
                    webApiService.judgeFinish();
                    Thread.sleep(3000L);
                }catch (Exception e) {
                    log.error("【判断整车是否结束线程出现了异常】", e);
                }
            }
        });

        //监听当前任务的照片是否全部审核完成
        Thread taskFinishThread = new Thread(() -> {
            while (true){
                try {
                    webApiService.judgeTaskFinish();
                    Thread.sleep(3000L);
                } catch (Exception e) {
                    log.error("【监听当前任务的照片是否全部审核完成出现了异常】", e);
                }
            }
        });

        judgeThread.start();
        taskFinishThread.start();
    }
}
